package cn.wolfcode.shop.mapper;

import cn.wolfcode.shop.domain.Good;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

@Mapper
public interface GoodMapper {

    // select * from t_goods where id in (1,2)
    @SelectProvider(type = GoodSelectProvider.class,method = "queryByIds")
    List<Good> queryByIds(@Param("ids") List<Long> ids);

    class GoodSelectProvider{
        // 返回值就是执行的sql
        public String queryByIds(@Param("ids") List<Long> ids){
            StringBuilder sb = new StringBuilder(50);
            sb.append("select * from t_goods ");
            if (ids.size()>0){
                sb.append("where id in (");
                for (int i = 0; i < ids.size(); i++) {
                    if (i!=0){
                        sb.append(",");
                    }
                    sb.append(ids.get(i));
                }
                sb.append(")");
            }
            System.err.println(sb);
            return sb.toString();
        }
    }
}
